import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';

class ToolsCommon {
  // 0 网络运行 1 单机运行
  static int applcation_model = 0;

  static EventBus wordEventBus = EventBus();

  static message(BuildContext context, String title, String info, dynamic confirmFunc) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: Text(info),
            actions: [
              TextButton(
                  onPressed: () async {
                    Navigator.of(context).pop();
                    confirmFunc();
                  },
                  child: Text("确认"))
            ],
          );
        });
  }

  static confirm(BuildContext context, String title, String info, dynamic confirmFunc, dynamic cancelFunc) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: Text(info),
            actions: [
              TextButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                    cancelFunc();
                  },
                  child: Text("取消")),
              TextButton(
                  onPressed: () async {
                    Navigator.of(context).pop();
                    confirmFunc();
                  },
                  child: Text("确认"))
            ],
          );
        });
  }

  static String getNowTimeStr() {
    DateTime n = DateTime.now();
    var y = n.year.toString();
    var m = n.month.toString();
    var d = n.day.toString();
    var h = n.hour.toString();
    var mm = n.minute.toString();
    var s = n.second.toString();

    if (m.length < 2) m = "0" + m;
    if (d.length < 2) d = "0" + d;
    if (h.length < 2) h = "0" + h;
    if (mm.length < 2) mm = "0" + mm;
    if (s.length < 2) s = "0" + s;

    return "${y}${m}${d}${h}${mm}${s}";
  }

  static bool isDesktop(context)
  {
    TargetPlatform platform = Theme.of(context).platform;
    if(TargetPlatform.android == platform || TargetPlatform.iOS == platform)
      {
        return false;
      }
    return true;
  }
}
